package com.twu.biblioteca.impl;

import com.twu.biblioteca.entity.Book;

import java.util.List;
import java.util.Scanner;

public class OperateBook {
    public boolean showTheListOfAllBooks(List<Book> allBook) {
        boolean flag = false;

        try {
            int i;
            for(i = 0; i < allBook.size(); i++) {
                Book book = new Book();
                book = allBook.get(i);
                System.out.println(i+1 + ". " + book.getBookTitle());
            }
            System.out.println(i+1 + ". Return to the home menu");
            i++;
            System.out.println(i+1 + ". Exit");
            System.out.println(">> Please select the book to be reserved:          ");
            flag = true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }

    public String getSelectedChoiceId() {
        Scanner sc = new Scanner(System.in);
        String selectedChoiceId = sc.nextLine();
        return selectedChoiceId;
    }

    public String selectBook(String selectedChoiceId) {
        String theResultOfSelectBook = null;

        if(selectedChoiceId.equals("1")||selectedChoiceId.equals("3")||selectedChoiceId.equals("6")) {
            System.out.println(">> Sorry we don't have that book yet.\n");
            theResultOfSelectBook = "redo";
        }
        else if(selectedChoiceId.equals("2")||selectedChoiceId.equals("4")||selectedChoiceId.equals("5")||selectedChoiceId.equals("7")) {
            System.out.println(">> Thank You! Enjoy the book.\n");
            theResultOfSelectBook = "redo";
        }
        else if(selectedChoiceId.equals("8")) {
            theResultOfSelectBook = "goToMainMenu";
        }
        else if(selectedChoiceId.equals("9")) {
            theResultOfSelectBook = "exit";
        }
        else {
            System.out.println(">> Select a valid option!!                              \n");
            theResultOfSelectBook = "redo";
        }

        return theResultOfSelectBook;
    }
}
